﻿using HighDiveAdmin.Handlers;
using HighDiveEngine.Aggregates;
using HighDiveEngine.Model;
using HighDiveEngine.Resources;

namespace UnitTestHighDive
{
    public static class UnitTestMockObjects
    {
        #region MockObjects
        public static Contest _contest1;
        public static Diver _diver1;
        public static Diver _diver2;
        public static Diver _diver3;

        public static Judge _judge1;
        public static Judge _judge2;
        public static Judge _judge3;

        public static Dive _dive11;
        public static Dive _dive21;
        public static Dive _dive31;

        public static Dive _dive12;
        public static Dive _dive22;
        public static Dive _dive32;

        public static DiveScore _diveScore111;
        public static DiveScore _diveScore112;
        public static DiveScore _diveScore113;

        public static DiveScore _diveScore211;
        public static DiveScore _diveScore212;
        public static DiveScore _diveScore213;

        public static DiveScore _diveScore311;
        public static DiveScore _diveScore312;
        public static DiveScore _diveScore313;

        public static DiveScore _diveScore121;
        public static DiveScore _diveScore122;
        public static DiveScore _diveScore123;

        public static DiveScore _diveScore221;
        public static DiveScore _diveScore222;
        public static DiveScore _diveScore223;

        public static DiveScore _diveScore321;
        public static DiveScore _diveScore322;
        public static DiveScore _diveScore323; 
        #endregion

        #region ResetObjects
        public static void ResetObjects()
        {
            _contest1 = new Contest
            {
                Country = "Dödsstjärnan",
                City = "Simhallsavdelningen",
                Club = "Solens Simklubb",
                Date = "2015-02-04",
                Name = "Galaxmästerskapen",
                JudgeList = new JudgeList(3),
                DiveHistory = new DiveList(),
                DiveQueue = new DiveList(),
                Status = ContestStatus.Started
            };

            //Divers
            _diver1 = new Diver { IdNumber = "011133", FirstName = "Egbert", LastName = "hej", Gender = Gender.Male, StartNumber = 1 };
            _diver2 = new Diver { IdNumber = "246345", FirstName = "Egberta", LastName = "hej", Gender = Gender.Female, StartNumber = 2 };
            _diver3 = new Diver { IdNumber = "234624", FirstName = "Bert", LastName = "hej", Gender = Gender.Male, StartNumber = 3 };

            //Judges
            _judge1 = new Judge { IdNumber = "191260", FirstName = "Kalle", LastName = "hej", Gender = Gender.Male, JudgeNumber = 1 };
            _judge2 = new Judge { IdNumber = "347358", FirstName = "Karin", LastName = "hej", Gender = Gender.Female, JudgeNumber = 2 };
            _judge3 = new Judge { IdNumber = "467845", FirstName = "Berit", LastName = "hej", Gender = Gender.Female, JudgeNumber = 3 };

            //Dives
            _dive11 = new Dive { Diver = _diver1, DiveCode = "5112A", DiveNumber = 1, DiveHeight = 10, QueueOrderNumber = 1 };
            _dive11.CalculateDifficulty();
            _dive21 = new Dive { Diver = _diver2, DiveCode = "5112A", DiveNumber = 1, DiveHeight = 10, QueueOrderNumber = 2 };
            _dive21.CalculateDifficulty();
            _dive31 = new Dive { Diver = _diver3, DiveCode = "5112A", DiveNumber = 1, DiveHeight = 10, QueueOrderNumber = 3 };
            _dive31.CalculateDifficulty();

            //Dives
            _dive12 = new Dive { Diver = _diver1, DiveCode = "404B", DiveNumber = 2, DiveHeight = 10, QueueOrderNumber = 4 };
            _dive12.CalculateDifficulty();
            _dive22 = new Dive { Diver = _diver2, DiveCode = "404B", DiveNumber = 2, DiveHeight = 10, QueueOrderNumber = 5 };
            _dive22.CalculateDifficulty();
            _dive32 = new Dive { Diver = _diver3, DiveCode = "404B", DiveNumber = 2, DiveHeight = 10, QueueOrderNumber = 6 };
            _dive32.CalculateDifficulty();

            _contest1.JudgeList.Add(_judge1);
            _contest1.JudgeList.Add(_judge2);
            _contest1.JudgeList.Add(_judge3);
            _contest1.JudgeList.GenerateIdStrings();

            _contest1.DiveHistory.Add(_dive11);
            _contest1.DiveHistory.Add(_dive21);
            _contest1.DiveHistory.Add(_dive31);

            _contest1.DiveQueue.Add(_dive12);
            _contest1.DiveQueue.Add(_dive22);
            _contest1.DiveQueue.Add(_dive32);

            //Divescores
            _diveScore111 = new DiveScore { Judge = _judge1, Score = 5.0 };
            _diveScore112 = new DiveScore { Judge = _judge2, Score = 5.5 };
            _diveScore113 = new DiveScore { Judge = _judge3, Score = 6.0 };

            _diveScore211 = new DiveScore { Judge = _judge1, Score = 5.0 };
            _diveScore212 = new DiveScore { Judge = _judge2, Score = 5.5 };
            _diveScore213 = new DiveScore { Judge = _judge3, Score = 6.0 };

            _diveScore311 = new DiveScore { Judge = _judge1, Score = 5.0 };
            _diveScore312 = new DiveScore { Judge = _judge2, Score = 5.5 };
            _diveScore313 = new DiveScore { Judge = _judge3, Score = 6.0 };

            _dive11.DiveScoreList.Add(_diveScore111);
            _dive11.DiveScoreList.Add(_diveScore112);
            _dive11.DiveScoreList.Add(_diveScore113);
            _dive11.CalculateTotalScore();

            _dive21.DiveScoreList.Add(_diveScore211);
            _dive21.DiveScoreList.Add(_diveScore212);
            _dive21.DiveScoreList.Add(_diveScore213);
            _dive21.CalculateTotalScore();

            _dive31.DiveScoreList.Add(_diveScore311);
            _dive31.DiveScoreList.Add(_diveScore312);
            _dive31.DiveScoreList.Add(_diveScore313);
            _dive31.CalculateTotalScore();

        } 
        #endregion

        #region SqlSetup
        public static void ResetDatabase()
        {
            
            //Persons-table
            DbHandler.Instance.DbEngine.SqlCommand("DELETE FROM Persons;");

            //Judges-table
            DbHandler.Instance.DbEngine.SqlCommand("DELETE FROM Judges;");

            //Contests-table
            DbHandler.Instance.DbEngine.SqlCommand("DELETE FROM Contests;");

            //Dives-table
            DbHandler.Instance.DbEngine.SqlCommand("DELETE FROM Dives;");

            //DiveScores-table
            DbHandler.Instance.DbEngine.SqlCommand("DELETE FROM DiveScores;");

            //Divers-table
            DbHandler.Instance.DbEngine.SqlCommand("DELETE FROM Divers;");
        }
        #endregion
    }
}
